//
//  WDWorderOrdMainVehSingleImageView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/9/3.
//

#import "WDWorderOrdMainVehSingleImageView.h"

@interface WDWorderOrdMainVehSingleImageView ()

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *imageUrl;

@property (nonatomic, strong) UIImageView *thumalImgView;

@property (nonatomic, strong) UILabel *titleLabel;


- (void)initWithThumalImgView;

- (void)initWithTitleLabel;

@end

@implementation WDWorderOrdMainVehSingleImageView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor whiteColor];
}

- (void)initWithThumalImgView {
    if (!_thumalImgView) {
        CGRect frame = CGRectMake(0, 0, self.width, self.height - 5 - 18);
        _thumalImgView = [UIImageView createWithImageView:self frame:frame defaultImage:nil propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.layer.cornerRadius = 5;
            imageView.layer.masksToBounds = YES;
//            imageView.backgroundColor = [UIColor systemPinkColor];
            imageView.userInteractionEnabled = YES;
        }];
        
        @weakify(self);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            @strongify(self);
            if (self.touchShowPicBlock) {
                self.touchShowPicBlock(self.thumalImgView, self.imageUrl);
            }
        }];
        [self.thumalImgView addGestureRecognizer:tap];
    }
    if (self.imageUrl) {
        [self.thumalImgView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl] placeholderImage:nil];
    }
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(0, self.thumalImgView.bottom + 5, self.width, 18);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:13 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
            label.textAlignment = NSTextAlignmentCenter;
        }];
    }
    if (self.title) {
        _titleLabel.text = self.title;
    }
}

- (void)updateWithViewTitle:(NSString *)title imageUrl:(NSString *)imageUrl {
    self.title = title;
    self.imageUrl = imageUrl;
    
    [self initWithThumalImgView];

    [self initWithTitleLabel];
}

@end
